FROM nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04

WORKDIR /app

# 更新包列表并安装 Python 3.8 和 pip
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  --mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update && \
    apt-get install -y python3.8 python3.8-distutils python3-pip libgl1 fonts-dejavu && \
    rm -rf /var/lib/apt/lists/*

# 创建 symlink，使 python3 指向 python3.8
# RUN ln -s /usr/bin/python3.8 /usr/bin/python3

RUN pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple
RUN pip3 config set install.trusted-host mirrors.aliyun.com

# 更新pip 至最新
RUN --mount=type=cache,target=/root/.cache/pip-install \
    pip3 install pip -U

COPY requirements.txt .

RUN --mount=type=cache,target=/root/.cache/pip-install \
    pip3 install -r requirements.txt

COPY src/ /app/src/
COPY model/ /app/model/
COPY conf/ /app/conf/

RUN mkdir /app/log

COPY conf/config.ini /app/conf/config.ini

EXPOSE 28080
ENV PYTHONPATH="/app/src"
ENTRYPOINT ["python3", "/app/src/server/main_server.py"]